/**
 * Created by SJay on 2017/12/27.
 */
export default   function (activeCart) {
  var sessionId = localStorage.getItem('sessionId')
  var storeCode = localStorage.getItem('storeCode')
  var cartArray = localStorage.getItem('cartArray')
  sessionId = sessionId == 'undefined' ? '' : sessionId
  cartArray = cartArray ? JSON.parse(cartArray) : []
  if (!activeCart || sessionId) {
    return cartArray
  }
  var cartList = {
    storeCode,
    shoppingCartLists: activeCart
  }

  var cartListIndex = cartArray.findIndex(
    (item) => {
      return item.storeCode == storeCode
    })

  if (cartListIndex == -1) {
    cartArray.push(cartList)

  } else {
    cartArray.splice(cartListIndex, 1, cartList)
  }
  localStorage.setItem('cartArray', JSON.stringify(cartArray))
  return cartArray
}
